<?php

require_once 'Zend/View/Helper/Abstract.php';

class Core_View_Helper_Admin_SelectGroup extends Zend_View_Helper_Abstract
{
    public function selectGroup($name, $value = null, $attribs = null, $currentGroup = null, $exclude = null, $excludeCurrent = true)
    {
        $mdlGroup = new Model_Group();
        $groups = $mdlGroup->getGroupNamesArray($exclude);

        $options[] = $this->view->getTranslation('Select Group');

        if (count($groups) > 0) {
            foreach ($groups as $group) {
                if (false == $excludeCurrent || (empty($currentGroup) || $group['name'] != $currentGroup)) {
                    if (isset($group['label']) && !empty($group['label'])) {
                        $options[$group['name']] = $group['label'];
                    } else {
                        $options[$group['name']] = $group['name'];
                    }
                }
            }
        }

        $form   = new Core_Form();
        $select = $form->createElement('select', $name, array(
            'multiOptions'  => $options,
        ));
        if (is_array($value)) {
            $select->setValue($value);
        }
        if (is_array($attribs)) {
            $select->setAttribs($attribs);
        }
        return $select;
    }
}